package com.ymatou.iapi.godmch.testcase;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.bindmchBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.getAfterServiceInfoByIdListBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.getAfterServiceInfoByIdListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.afterserviceinfo;
import com.ymttest.database.model.afterserviceinfoExample;
import com.ymttest.database.sqlwapper.godmch.afterserviceinfoWapper;
/**
*批量查询售后信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getAfterServiceInfoByIdList{
	private static getAfterServiceInfoByIdListBean bean;
	private static getAfterServiceInfoByIdListCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量查询售后信息");
	}

	@Before
	public void caseUp() {
		bean=new getAfterServiceInfoByIdListBean();
		call=new getAfterServiceInfoByIdListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	 private void  check_verify() throws InterruptedException, JSONException
	    {
	    	Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
	    	
	    	List<afterserviceinfo> return_infos=call.getList();
	    	afterserviceinfoWapper infoWapper=new afterserviceinfoWapper();
			afterserviceinfoExample Example=new afterserviceinfoExample();
			afterserviceinfoExample.Criteria criteria = Example.createCriteria();
			
			criteria.andMchIdIn(bean.getMchIdList());
			criteria.andParentMchIdIn(bean.getParentMchIdList());
			
			//Example.setOrderByClause(" createTime desc");
			
			List<afterserviceinfo> DB_infos=infoWapper.selectByExample(Example);
			Logger.verifyEquals(DB_infos.size(), return_infos.size(), "数据库返回的条数与接口返回的条数一致");
			for(int i=0;i<DB_infos.size();i++)
			{
				
				afterserviceinfo DB_info=DB_infos.get(i);
				afterserviceinfo return_info=return_infos.get(i);
				Logger.comment("mchId:"+DB_info.getMchId());
				Logger.comment("parentMchId:"+DB_info.getParentMchId());
				
				Logger.verifyEquals(DB_info.getAddress(), return_info.getAddress(), "验证第"+(i+1)+"条Address");
				Logger.verifyEquals(DB_info.getMchId(), return_info.getMchId(), "验证第"+(i+1)+"条MchId");
				Logger.verifyEquals(DB_info.getRemark(), return_info.getRemark(), "验证第"+(i+1)+"条Remark");
				Logger.verifyEquals(DB_info.getWeChat(), return_info.getWeChat(), "验证第"+(i+1)+"条WeChat");
			}
	    }
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAfterServiceInfoByIdList_001() {
		Logger.start(true,"正例-批量查询售后信息-一个代理对应一个渠道");
		try {
			
			//代理用户
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean);
			
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(false);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			//创建渠道1
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//渠道1 邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			//创建渠道2
		    createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId_agent);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//绑定一个渠道与另外一个渠道绑定
			bindmchBean bindmchBean=GodmchManageCallService.InitbindmchBean(mchId_agent, createCodeCall.getCode());
			GodmchManageCallService.bindmchcall(bindmchBean);
			List<Integer> mchIds=new ArrayList();
			mchIds.add(mchId_agent);
			List<Integer>parentMchIds=new ArrayList();
			parentMchIds.add(mchId);
			
			GodmchManageCallService.AddAfterService(mchId,mchId_agent);
			bean.setMchIdList(mchIds);
			bean.setParentMchIdList(parentMchIds);
			call.setData(bean);
			call.callService();			
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAfterServiceInfoByIdList_002() {
		Logger.start(true,"正例-批量查询售后信息-一个渠道对应多个代理");
		try {
			
			//代理用户
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean);
			
			usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent2 = DGUserCallService.UserCreateCall(usercreateBean);
			
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(false);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			//创建渠道1
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//渠道1 邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			
			
			//创建渠道2
		    createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId_agent);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
		    createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId_agent2);
				GodmchManageCallService.createmchCallForChannel(createBean1);
				
			//绑定一个渠道与另外一个渠道绑定
			bindmchBean bindmchBean=GodmchManageCallService.InitbindmchBean(mchId_agent, createCodeCall.getCode());
			GodmchManageCallService.bindmchcall(bindmchBean);
			
			bindmchBean bindmchBean2=GodmchManageCallService.InitbindmchBean(mchId_agent2, createCodeCall.getCode());
			GodmchManageCallService.bindmchcall(bindmchBean2);
			
			List<Integer> mchIds=new ArrayList();
			mchIds.add(mchId_agent);
			mchIds.add(mchId_agent2);
			List<Integer>parentMchIds=new ArrayList();
			parentMchIds.add(mchId);
			
			GodmchManageCallService.AddAfterService(mchId,mchId_agent);
			Thread.sleep(1000);
			GodmchManageCallService.AddAfterService(mchId,mchId_agent2);
			bean.setMchIdList(mchIds);
			bean.setParentMchIdList(parentMchIds);
			call.setData(bean);
			call.callService();				
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAfterServiceInfoByIdList_003() {
		Logger.start(true,"正例-批量查询售后信息-一个代理对应多个渠道");
		try {
			
			//代理用户
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean);
			
			usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId1= DGUserCallService.UserCreateCall(usercreateBean);
			
			usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId2 = DGUserCallService.UserCreateCall(usercreateBean);
			
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(false);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			//创建渠道1
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId1);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//渠道1 邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId1, true);
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			
			
			//创建渠道2
		    createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId2);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			 createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId2, true);
			CreateCodeCall createCodeCall2=GodmchManageCallService.createCodeCall(createCodeBean);

			
			List<createmchBean>  createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(mchId1, mchId_agent);
				GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
						createmchBean[0]));
				
//		 List<createmchBean>  createmchList2=GodmchManageCallService.InitcreatemchBeanForAgent(mchId2, mchId_agent);
//		 GodmchManageCallService.createmchCallForAgent(createmchList2.toArray(new
//						createmchBean[0]));
		 
			//绑定一个渠道与另外一个渠道绑定
			bindmchBean bindmchBean=GodmchManageCallService.InitbindmchBean(mchId_agent, createCodeCall2.getCode());
			GodmchManageCallService.bindmchcall(bindmchBean);
			
			List<Integer> mchIds=new ArrayList();
			mchIds.add(mchId_agent);
			List<Integer>parentMchIds=new ArrayList();
			parentMchIds.add(mchId1);
			parentMchIds.add(mchId2);
			
			GodmchManageCallService.AddAfterService(mchId1,mchId_agent);
			Thread.sleep(1000);
			GodmchManageCallService.AddAfterService(mchId2,mchId_agent);
			bean.setMchIdList(mchIds);
			bean.setParentMchIdList(parentMchIds);
			call.setData(bean);
			call.callService();				
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAfterServiceInfoByIdList_004() {
		Logger.start(true,"正例-批量查询售后信息-mchId为空");
		try {
			
			//代理用户
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean);
			
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(false);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			//创建渠道1
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//渠道1 邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			//创建渠道2
		    createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId_agent);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//绑定一个渠道与另外一个渠道绑定
			bindmchBean bindmchBean=GodmchManageCallService.InitbindmchBean(mchId_agent, createCodeCall.getCode());
			GodmchManageCallService.bindmchcall(bindmchBean);
			List<Integer> mchIds=new ArrayList();
			//mchIds.add(mchId_agent);
			List<Integer>parentMchIds=new ArrayList();
			parentMchIds.add(mchId);
			
			GodmchManageCallService.AddAfterService(mchId,mchId_agent);
			//bean.setMchIdList(mchIds);
			bean.setParentMchIdList(parentMchIds);
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAfterServiceInfoByIdList_005() {
		Logger.start(true,"正例-批量查询售后信息-ParentMchIdList为空");
		try {
			
			//代理用户
			UserCreateBean usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean);
			
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(false);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			//创建渠道1
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//渠道1 邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			//创建渠道2
		    createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId_agent);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			//绑定一个渠道与另外一个渠道绑定
			bindmchBean bindmchBean=GodmchManageCallService.InitbindmchBean(mchId_agent, createCodeCall.getCode());
			GodmchManageCallService.bindmchcall(bindmchBean);
			List<Integer> mchIds=new ArrayList();
			mchIds.add(mchId_agent);
			List<Integer>parentMchIds=new ArrayList();
			//parentMchIds.add(mchId);
			
			GodmchManageCallService.AddAfterService(mchId,mchId_agent);
			bean.setMchIdList(mchIds);
			//bean.setParentMchIdList(parentMchIds);
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}